---
category: Misc
created: '2020-05-02'
title: Check if the code is running in the browser
updated: '2021-10-13'
---

**JavaScript version**

```js isBrowser.js
const isBrowser = typeof window === 'object' && typeof document === 'object';
```

**TypeScript version**

```ts isBrowser.ts
const isBrowser: boolean = typeof window === 'object' && typeof document === 'object';
```
